home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1994-02-05 | 3.2 KB | 160 lines |
- >HeapTest
- Squished by Lofty's !Shrink vsn 3.01 on 05-Feb-94
- _heap_init
- quit% =
- a% = 0
- b% = 0
- blk% = 0
- amount$ = ""
- g = 0
- '"Slot size currently ";~_SlotSize%
- "Select from..."
- "1= fetch"'"2= return"'"3= resize"'"4= quit"
- g =
- - 48
-
- "size to fetch: &"a$
-
- a$ <> ""
- a% =
- ("&" + a$)
- ! blk% =
- _heap_get(a%)
-
- blk% > 0
- 0
- '"Block allocated at &" +
- ~blk%
-
- 0
- '"Unable to claim enough memory"
-
-
- "
- "block to return: &"a$
-
- a$ <> ""
- a% =
- ("&" + a$)
- b% = a%
-
- _heap_release(a%)
-
- (a% = 0)
- $;
- '"Block at &" +
- ~b% + " has been released"
-
- &,
- '"No block exists at &"+
-
-
- *"
- "Block to resize: &"a$
- +0
- "Amount (-ve to decrease): &"amount$
-
- a$ <> ""
- a% =
- ("&" + a$)
- b% = a%
- /(
- _heap_resize(a%,
- (amount$))
-
- (a% > 0)
- 1<
- '"Block at &" +
- ~b% + " has been resized ";
- 25
- a% <> b%
- "(now at &"+
- ~a%+")"
-
- 48
- a% = -3
- '"No block exists at &"+
- 5<
- a% = -2
- '"Unable to claim enough memory"
- 6>
- a% = -1
- '"Block size is now 0 or negative"
-
-
- quit% =
- quit%
- _heap_init
- _Heap% =
- "OS_ReadMemMapInfo"
- _PageSize%
- _SlotSize% = _Heap% - &8000
- "Wimp_SlotSize",_SlotSize% + _PageSize%,-1
- _SlotSize%
- D"_HeapEnd% = _SlotSize% + &8000
- _HeapEnd% <= _Heap%
- 0,"Can't claim space for heap"
- "OS_Heap",0,_Heap%,,_HeapEnd% - _Heap%
- _heap_get(size%)
- maxfree%,nrpages%,oldheapend%,ptr%
- "OS_Heap",1,_Heap%
- ,,maxfree%
- size% > maxfree%
- M, nrpages% = 1 + (size%
- _PageSize%) :
- "Wimp_SlotSize",_SlotSize% + nrpages% * _PageSize%,-1
- _SlotSize%
- oldheapend% = _HeapEnd%
- P& _HeapEnd% = _SlotSize% + &8000
- "OS_Heap",5,_Heap%,,_HeapEnd% - oldheapend%
- "OS_Heap",1,_Heap%
- ,,maxfree% :
- size% > maxfree%
- ptr% = -1
- "OS_Heap",2,_Heap%,,size%
- ,,ptr%
- = ptr%
- _heap_release(
- ptr%)
- maxfree%,nrpages%,flg%
- "XOS_Heap",3,_Heap%,ptr%
- ;flg%
- (flg%
- 1) = 0
- "OS_Heap",1,_Heap%
- ,,maxfree%
- maxfree% > _PageSize%
- nrpages% = 0 :
- b
- c5
- "XOS_Heap",5,_Heap%,,-_PageSize%
- ;flg%
-
- (flg%
- 1) = 0
- nrpages% += 1
-
- (flg%
- 1) <> 0
- nrpages% > 0
- iO
- "Wimp_SlotSize",_SlotSize% - nrpages% * _PageSize%,-1
- _SlotSize%
- j( _HeapEnd% = _SlotSize% + &8000
- k
- l?
- "OS_Heap",5,_Heap%,,(_HeapEnd% - _Heap%) - _Heap%!12
- ptr% = 0
- ptr% = -1
- _heap_resize(
- ptr%,change%)
- flg%
- "XOS_Heap",6,_Heap%,ptr%
- ;flg%
- (flg%
- ptr% = -3
- "XOS_Heap",4,_Heap%,ptr%,change%
- ,,ptr%;flg%
- (flg%
- ptr% = -2
-